<template>
	<div class="container">
		<h3 class="header-title clearfix">
			<span></span>
			<p>岗位招聘管理</p>
		</h3>
		<!-- 导航栏 -->
		<comNavTabs :navList="navList" @switch="tabSwitch"></comNavTabs>
		<!-- 搜索条件：注册时间，用户名，电话等 -->
		<comSearch v-if="searchList.show" ref="search" @searchList="searchTermList" :options="searchList"></comSearch>
		<!-- 数据展示的列表 -->
		<comTable :options="tableList"
			@openExamine="openExamineDialog"
			@openRemind="openRemindDialog"	
		></comTable>
		<!-- 待审核-审核弹窗 -->
		<entExamine ref="examine" @Refresh="tabSwitch(navList.index)" :options="examine"></entExamine>
		<!-- 未付费-操作提醒弹窗 --><!-- 已审核-下架操作弹窗 -->
		<praFeedback ref="remind" :options="remind" @subRemind="submitRemind"></praFeedback>
		
		<!-- 分页器 -->
		<div class="pageBox">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="pageChange"
				:current-page.sync="cur"
				:page-sizes="[10, 20, 30, 50, 100]"
				:page-size="pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="totalNum"
				background
			></el-pagination>
		</div>
		
	</div>
</template>

<script>
import jobsJson from "../../assets/jobs.json"
export default {
	components:{
		comNavTabs: () => import("../common/comNavTabs.vue"),
		comSearch: () => import("../common/comSearch.vue"),
		comTable: () => import("../common/comTable.vue"),
		entExamine: () => import("../common/entExamine.vue"),
		praUnreported: () => import("../common/praUnreported.vue"),
		praFeedback: () => import("../common/praFeedback.vue")
	},
	data(){
		// let amapManager = new VueAMap.AMapManager();
		return {
			userinfo:{},				//当前登录账号的人员信息
			/* 导航栏列表数据 */
			navList:{
				index:0,				//当前是在哪个tab栏
				isShow: true,			//不显示未通过这栏
				data:[
					{title:'待审核'},
					{title:'未通过'},
					{title:'已审核'},
					{title:'已下架'},
					{title:'未付费'},
					{title:'已付费'}
				]	
			},
			/* 搜索栏数据 */
			searchList:{
				show:false,				//是否显示搜索栏
				noTime:false,			//有没有时间
				noTelphone:false,		//有没有电话
				noUser:false,			//有没有实名用户名
				noSalary:false,			//有没有薪资待遇
				noEmployer:false,		//有没有雇主
				noCity:false,			//有没有所在地
				noPosition:false		//有没有职位名称
			},
			/* 保留下来的搜索数据 */
			searchData:{},
			tableList:{
				list:[
					/* {title:'姓名',prop:'username',isClick:false},
					{title:'手机号',prop:'telphone',isClick:false},
					{title:'预约时间',prop:'appointment',isClick:false},
					{title:'自评报告',prop:'report',isClick:true} */
				],
				noOperation:true,	//是否有操作项
				operation:[			//操作项内容
					// 
				],
				data:[				//请求到的表格数据
					/* {
						username: '谢镔',					//姓名
						telphone: '16666666666',			//手机号
						appointment: '2016-05-02 11:30',	//预约时间
						report: '查看',						//自评报告
					} */
				]
			},
			examine:{
				userinfo:{},							//当前雇主提交岗位的信息
				statusIndex:0,							//当前的tab值
				jobTitle:'',							//岗位名称
				salary:'',								//薪资
				recruitingNumbers:2,					//招聘人数
				ageRange:'',							//年龄范围
				educationalRequirements:'',				//学历要求
				workExperience:'',						//工作经验
				workAdress: '',							//工作地点
				updateTime:'',							//发布时间
				jobDescription:'',						//职位描述
				jobRequirements:'',						//任职要求
				status: '1',							//时薪还是月薪  1-月薪 2-时薪
				workDays: 4,							//时薪长期每周工作天数
				hourlyState: '1',						//时薪是长期还是短期  1-长期 2-短期
				zoom:16,								//地图放大缩小的比例
				center:[121.506377,31.245105],			//底图的经纬度
				skillListPre:[],						//技能
				skillListNext:[],						//技能
				dataList:{								//测评操作记录
					list:[
						{title:'门店名称',prop:'branchName',isClick:false},
						{title:'操作人员姓名',prop:'auditorName',isClick:false},
						{title:'操作状态',prop:'mystatus',isClick:false},
						{title:'操作备注',prop:'operationCause',isClick:false},
						{title:'操作时间',prop:'createTime',isClick:false},
						
					],
					noOperation:false,	//是否有操作项
					data:[				//请求到的表格数据
						/* {
							branchName: '发才网线下辅导站1号店',			//线下门店
							auditorName: '小明',							//操作员
							createTime: '2020-03-09 11:30',				//操作时间
							mystatus: '未通过审核',						//操作状态
							operationCause: '能力不足',					//操作备注
						} */
					]
				}
			},
			remind:{
				userinfo:{},						//用户信息
				title:"提醒",						//弹窗标题
				noNav:false,						//是否有选项
				eventName:'subRemind',				//提交事件的名称
			},
			/* 分页功能数据 */
			cur:1,									//当前是在第几页
			pageSize: 10,							//每页显示多少条数据
			totalNum: 0,							//总共有多少条数据,根据这个数据去适配页数
			
		}
	},
	created(){
		this.tabSwitch(0);
		this.userinfo = JSON.parse(localStorage.getItem('userinfo'));
	},
	watch:{
		'navList.index'(){
			let index = this.navList.index;
			this.examine.statusIndex = index;
		}
	},
	methods:{
		tabSwitch(index){
			console.log(this.cur);
			this.navList.index = index;
			/* 请求接口,获取数据 */
			let data = [];
			if(index == 0){
				this.searchList.show = false;
				this.tableList.list = [
					{title:'雇主姓名',prop:'username',isClick:false},
					{title:'职位名称',prop:'jobTitle',isClick:false},
					{title:'工作地点',prop:'address',isClick:false},
					{title:'薪资待遇',prop:'salary',isClick:false},
					{title:'招聘人数',prop:'recruitingNumbers',isClick:false},
					{title:'发布时间',prop:'updateTime',isClick:false}
				];
				this.tableList.noOperation = true;
				this.tableList.operation = [
					{name:'审核',isBtn:false,title:'openExamine'}
				];
				this.tableList.data = [
					/* {
						username: '谢镔',					//雇主姓名
						jobTitle: '月嫂',					//职位名称
						address: '上海市-闵行区',				//工作地点
						salary: '6k-7k',					//薪资待遇
						recruitingNumbers: 2,				//招聘人数
						updateTime: '2016-05-02 11:30',		//发布时间
					} */
				];
			}else if(index == 1){
				this.searchList.show = false;
				this.tableList.list = [
					{title:'雇主姓名',prop:'username',isClick:false},
					{title:'职位名称',prop:'jobTitle',isClick:false},
					{title:'工作地点',prop:'address',isClick:false},
					{title:'薪资待遇',prop:'salary',isClick:false},
					{title:'招聘人数',prop:'recruitingNumbers',isClick:false},
					{title:'发布时间',prop:'updateTime',isClick:false}
				];
				this.tableList.noOperation = true;
				this.tableList.operation = [
					{name:'查看',isBtn:false,title:'openExamine'}
				];
				this.tableList.data = [
					/* {
						username: '谢镔',					//雇主姓名
						jobTitle: '月嫂',					//职位名称
						address: '上海市-闵行区',				//工作地点
						salary: '6k-7k',					//薪资待遇
						recruitingNumbers: 2,				//招聘人数
						updateTime: '2016-05-02 11:30',		//发布时间
					} */
				];
			}else if(index == 2){
				this.searchList.show = true;
				this.searchList.noCity = true;	
				this.searchList.noPosition = true;	
				this.searchList.noSalary = true;	
				this.searchList.noEmployer = true;	
				this.tableList.list = [
					{title:'雇主姓名',prop:'username',isClick:false},
					{title:'职位名称',prop:'jobTitle',isClick:false},
					{title:'工作地点',prop:'address',isClick:false},
					{title:'薪资待遇',prop:'salary',isClick:false},
					{title:'招聘人数',prop:'recruitingNumbers',isClick:false},
					{title:'发布时间',prop:'updateTime',isClick:false}
				];
				this.tableList.noOperation = true;
				this.tableList.operation = [
					{name:'查看',isBtn:false,title:'openExamine'},
					{name:'下架',isBtn:false,title:'openRemind'},
					
				];
				this.tableList.data = [
					/* {
						username: '谢镔',					//雇主姓名
						jobTitle: '月嫂',					//职位名称
						address: '上海市-闵行区',				//工作地点
						salary: '6k-7k',					//薪资待遇
						recruitingNumbers: 2,				//招聘人数
						updateTime: '2016-05-02 11:30',		//发布时间
					} */
				];
			}else if(index == 3){
				this.searchList.show = true;
				this.searchList.noCity = true;	
				this.searchList.noPosition = true;	
				this.searchList.noSalary = true;	
				this.searchList.noEmployer = true;	
				this.tableList.list = [
					{title:'雇主姓名',prop:'username',isClick:false},
					{title:'职位名称',prop:'jobTitle',isClick:false},
					{title:'工作地点',prop:'address',isClick:false},
					{title:'薪资待遇',prop:'salary',isClick:false},
					{title:'招聘人数',prop:'recruitingNumbers',isClick:false},
					{title:'下架类型',prop:'shelvesType',isClick:false},
					{title:'发布时间',prop:'updateTime',isClick:false}
				];
				this.tableList.noOperation = true;
				this.tableList.operation = [
					{name:'查看',isBtn:false,title:'openExamine'},
				];
				this.tableList.data = [
					/* {
						username: '谢镔',					//雇主姓名
						jobTitle: '月嫂',					//职位名称
						address: '上海市-闵行区',				//工作地点
						salary: '6k-7k',					//薪资待遇
						recruitingNumbers: 2,				//招聘人数
						shelvesType:'平台下架',				//下架类型
						updateTime: '2016-05-02 11:30',		//发布时间
					} */
				];
			}else if(index == 4){
				this.searchList.show = true;
				this.searchList.noCity = true;	
				this.searchList.noPosition = true;	
				this.searchList.noSalary = true;	
				this.searchList.noEmployer = true;	
				this.tableList.list = [
					{title:'雇主姓名',prop:'username',isClick:false},
					{title:'职位名称',prop:'jobTitle',isClick:false},
					{title:'工作地点',prop:'address',isClick:false},
					{title:'入职人员姓名',prop:'name',isClick:false},
					{title:'入职时间',prop:'entrydate',isClick:false},
					{title:'过保障期时间',prop:'securityNumber',isClick:false},
					{title:'发布时间',prop:'updateTime',isClick:false},
					{title:'待支付费用',prop:'aggregateScore',isClick:false}
				];
				this.tableList.noOperation = true;
				this.tableList.operation = [
					{name:'提醒',isBtn:false,title:'openRemind'},
				];
				this.tableList.data = [
					/* {
						username: '谢镔',					//雇主姓名
						jobTitle: '月嫂',					//职位名称
						address: '上海市-闵行区',				//工作地点
						name: '小明',						//入职人员姓名
						entrydate: '2016-05-02 11:30',		//入职时间
						securityNumber: '2016-05-02 11:30',	//过保障期时间
						updateTime: '2016-05-02 11:30',		//发布时间
						aggregateScore: 150,				//待支付费用
					} */
				];
			}else if(index == 5){
				this.searchList.show = true;
				this.searchList.noCity = true;	
				this.searchList.noPosition = true;	
				this.searchList.noSalary = true;	
				this.searchList.noEmployer = true;	
				this.tableList.list = [
					{title:'雇主姓名',prop:'username',isClick:false},
					{title:'职位名称',prop:'jobTitle',isClick:false},
					{title:'工作地点',prop:'address',isClick:false},
					{title:'入职人员姓名',prop:'name',isClick:false},
					{title:'入职时间',prop:'entrydate',isClick:false},
					{title:'过保障期时间',prop:'securityNumber',isClick:false},
					{title:'发布时间',prop:'updateTime',isClick:false},
					{title:'已支付费用',prop:'payIntegral',isClick:false},
					{title:'支付时间',prop:'payDate',isClick:false}
				];
				this.tableList.noOperation = false;
				this.tableList.data = [
					/* {
						username: '谢镔',					//雇主姓名
						jobTitle: '月嫂',					//职位名称
						address: '上海市-闵行区',				//工作地点
						name: '小明',						//入职人员姓名
						entrydate: '2016-05-02 11:30',		//入职时间
						securityNumber: '2016-05-02 11:30',	//过保障期时间
						updateTime: '2016-05-02 11:30',		//发布时间
						payIntegral: 150,					//已支付费用
						payDate: '2016-05-02 11:30',		//支付时间
					} */
				];
			}
			this.getListData(index + 3);
		},
		// 根据条件查询列表
		searchTermList(data){
			let form = data;
			this.searchData = data;
			if(form.salary){
				if(form.salary === 1){
					form.payFloor = 0;
					form.payUpper = 1000;
				}else{
					jobsJson.moneyList.forEach(item => {
						if(item.value == form.salary){
							form.salary = item.label;
							form.payFloor = form.salary.split('-')[0];
							form.payUpper = form.salary.split('-')[1];
						}
					})
				}
				delete form.salary;
			}
			console.log(form);
			this.getListData(this.navList.index+3,form);
		},
		// 获取 3、待审核 4、未通过 5、已审核 6、已下架  7、未付费 8、已付费  列表数据
		getListData(index,form){
			console.log(this.cur);	
			let params = {
				pageNum: this.cur,
				pageSize: this.pageSize,
				shelvesType: index
			};
			if(index != 3 && index != 4){
				params = Object.assign(params,form);
			}
			console.log(params);
			this.$houseAxios.post('/housekeeping/Position/selectPositionStatus',params).then(res => {
				console.log(res);
				if(res.data.code === 1000){
					let result = res.data.data;
					this.totalNum = parseInt(result.totalNum);
					if(result.list.length == 0){
						this.tableList.data.splice(0);
					}else{
						this.tableList.data.splice(0);
						result.list.forEach(item => {
							if(item.shelvesType == 1){
								item.shelvesType = '平台下架';
							}else{
								item.shelvesType = '个人下架';
							}
							if(item.status == '2'){
								item.salary = item.wagePay + '元/小时';
							}else{
								item.salary = item.payFloor + '-' + item.payUpper + '元/月';
							}
							
							item.address = item.province + '-' + item.city + '-' + item.county + '\n' + item.address;
							jobsJson.jobNameList.forEach(num => {
								if(item.jobTitle === num.key){
									item.jobTitle = num.value;
								}
							})
							item.jobTitle
							this.tableList.data.push(item);
						})
					}
				}
				
			})
		},
		// 打开-待审核-审核弹窗
		openExamineDialog(index){
			this.examine.userinfo = index;
			this.examine.userinfo.name = this.userinfo.name;
			this.$houseAxios.post('/housekeeping/Position/selectListByPositionId',{positionId:index.positionId}).then(res => {
				console.log(res);
				if(res.data.code === 1000){
					let result = res.data.data;
					jobsJson.jobNameList.forEach(item => {
						if(item.key == result.jobTitle){
							this.examine.jobTitle = item.value;
						}
					})
					this.examine.workAdress = result.province + result.city + result.county + result.address;
					if(result.status == '1'){
						this.examine.salary = result.payFloor + '-' + result.payUpper + '元/月';
					}else{
						if(result.hourlyState == '1'){
							this.examine.workDays = JSON.parse(result.workingHours).length;
						}else{
							this.examine.workList = JSON.parse(result.workingHours);
						}
						this.examine.hourlyState = result.hourlyState;
						this.examine.salary = result.wagePay + '元/小时';
					}
					this.examine.status = result.status;
					
					this.examine.recruitingNumbers = result.recruitingNumbers;
					this.examine.ageRange = result.ageRange + '岁';
					jobsJson.educaReqList.forEach(item => {
						if(item.value == result.educationalRequirements){
							this.examine.educationalRequirements = item.label;
						}
					})
					if(result.workExperience == '' || result.workExperience == null || result.workExperience == undefined ){
						this.examine.workExperience = '工作经验不限';
					}else{
						jobsJson.workExperList.forEach(item => {
							if(item.key == result.workExperience){
								this.examine.workExperience = item.value;
							}
						})
					}
					result.topicAnswer.forEach(item => {
						if(item.grade == '1'){
							item.per = 14;
						}else if(item.grade == '2'){
							item.per = 53;
						}else{
							item.per = 100;
						}
					})
					this.examine.skillListPre = result.topicAnswer.slice(0,16);
					this.examine.skillListNext = result.topicAnswer.slice(16);
					this.examine.updateTime = result.updateTime;
					this.examine.jobDescription = result.jobDescription;
					this.examine.jobRequirements = result.jobRequirements;
					this.$set(this.examine.center,0,parseFloat(result.longitude));
					this.$set(this.examine.center,1,parseFloat(result.latitude));
				}
			})
			if(this.examine.statusIndex == 1 || this.examine.statusIndex == 2 || this.examine.statusIndex == 3){
				this.$houseAxios.post('/housekeeping/Record/selectPosotionAuditorList',{positionid:index.positionId}).then(res => {
					console.log(res)
					if(res.data.code === 1000){
						this.examine.dataList.data.splice(0);
						res.data.data.forEach(item => {
							this.examine.dataList.data.push(item);
						})
					}
				})
			}
			this.$refs.examine.open();
		},
		// 未付费-操作提醒弹窗 和 已审核-下架操作弹窗 打开 
		openRemindDialog(index){
			console.log(index);
			this.remind.userinfo = index;
			if(this.navList.index == 2){
				this.remind.title = '下架理由';
			}else if(this.navList.index == 3){
				this.remind.title = '提醒';
			}
			this.$refs.remind.open();
		},
		// 提交-未付费-提醒弹窗数据并关闭弹窗
		submitRemind(data){
			console.log(data);
			/* 请求接口,提交数据 */
			if(this.navList.index == 2){
				let params = {
					positionid: this.remind.userinfo.positionId,
					auditorName: this.userinfo.name,
					status: 1,
					operationCause: data.textarea
				};
				this.$houseAxios.post('/housekeeping/Record/insertAuditorRecordStatus',params).then(res => {
					console.log(res);
					if(res.data.code === 1000){
						this.$message({
							message: '下架成功',
							type: 'success'
						})
						this.getListData(this.navList.index+3,this.searchData);
					}else{
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
			}else if(this.navList.index == 4){
				let params = {
					userid: this.remind.userinfo.userId,
					remindcontent: data.textarea,
					remark1: 0
				};
				this.$houseAxios.post('/housekeeping/message/remind',params).then(res => {
					console.log(res);
					if(res.data.code === 1){
						this.$message({
							message: '提醒成功',
							type: 'success'
						})
					}else{
						this.$message({
							message:res.data.code,
							type: 'warning'
						})
					}
				})
			}
			
			this.$refs.remind.close();
		},
		
		
		//当前页是第几页,点击的第几页的时候调用这个函数
		pageChange(p) {
			// 点击的时候传过来一个参数，这个参数就是所点击的当前页数，
			// 然后把这个当前页数转换成字符串形式赋值给page，
			// 然后把page这个参数传给search这个方法
			console.log(p);
			this.cur = p;
			this.getListData(this.navList.index+3,this.searchData);
		},
		//每页有多少条,10,20,50等,点击选择的时候调用这个方法
		handleSizeChange (val) {
			console.log(val);
			this.pageSize = val;
			this.getListData(this.navList.index+3,this.searchData);
		},
		//清空数据
		reset(){
			this.cur = 1;
			this.pageSize = 10;
			this.searchList = {};
			this.tableList = {};
		},
		// 将对象中属性值为空的属性删除
		deleteEmptyProperty(obj){
		    var object = obj;
		    for (var i in object) {
		        var value = object[i];
		        if (typeof value === 'object') {
		            if (Array.isArray(value)) {
		                if (value.length == 0) {
		                    delete object[i];
		                    continue;
		                }
		            }
		            this.deleteEmptyProperty(value);
		        } else {
		            if (value === '' || value === null || value === undefined) {
		                delete object[i];
		            }
		        }
		    }
		    return object;
		}
	}
}
</script>

<style scoped="scoped">
.container{
	background-color: #fff;
	height: 100%;
	padding-left: 20px;
}
.header-title{
	padding: 0 0 20px 0;
	border-bottom: 1px solid #D2D2D2;
}
.header-title span{
	width: 15px;
	height: 30px;
	background-color: #0064E4;
	margin-right: 20px;
	float: left;
}
.header-title p{
	float: left;
	font-weight: bold;
	line-height: 30px;
}
.pageBox{
	margin-top: 20px;
}
</style>
